<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/common_tag.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>权限—用户信息</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">

  </head>
  
  <body>
  	<script type="text/javascript">
  /** 添加-权限资源表格dialog  */
  function user_add_dlg_Fun() {
		$('<div/>').dialog({
			href : '${ctx}/security/user_add.jsp',
			width : 650,
			height : 500,
			iconCls:'icon-save',
			modal : true,
			title : '添加用户',
			buttons : [ {
				text : '保存',
				iconCls:'icon-save',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#user_addForm').form('submit', {
						url : '${ctx}/security/security_addUser.do',
						onSubmit: function () {
		                    return $(this).form('validate');
		                 },
						success : function(data) {
							d.dialog('destroy');
					    	$('#user_dg_table').datagrid('reload');
					        $.messager.alert('提示',data,'info');
						}
					});
				}
			}, {
				text : '取消',
				iconCls : 'icon-cancel',
				handler : function() {
					$(this).closest('.window-body').dialog('close');
				}
			}],
			onClose : function() {
				$(this).dialog('destroy')
			}
		});
	}

  /** 编辑修改-权限资源表格dialog  */
  function user_edit_dlg_Fun() {
	  if($('#user_dg_table').datagrid('getSelected')==null)return;
	  var id = $('#user_dg_table').datagrid('getSelected')['id'];
	  if(id=='')return;
		$('<div/>').dialog({
			href : '${ctx}/security/security_iniUser.do?id='+id,
			width : 650,
			height : 500,
			iconCls:'icon-save',
			modal : true,
			title : '修改用户信息',
			buttons : [ {
				text : '保存',
				iconCls:'icon-save',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#user_addForm').form('submit', {
						url : '${ctx}/security/security_addUser.do',
						onSubmit: function () {
		                    return $(this).form('validate');
		                 },
						success : function(data) {
		                	 d.dialog('destroy');
						     $('#user_dg_table').datagrid('reload');
						     $.messager.alert('提示',data,'info');
						}
					});
				}
			}, {
				text : '取消',
				iconCls : 'icon-cancel',
				handler : function() {
					$(this).closest('.window-body').dialog('close');
				}
			}],
			onClose : function() {
				$(this).dialog('destroy')
			}
		});
	}
  /** 删除-权限资源  */
  function user_del_Fun(id) {
	  if(id==null||id==''){
	  	if($('#user_dg_table').datagrid('getSelected')==null)return;
		id = $('#user_dg_table').datagrid('getSelected')['id'];
	  	}
		$.ajax({
			  type: 'POST',
			  url: '${ctx}/security/security_deleteRole.do',
			  data: { 'id': id } ,
			  success: function(data) {
			    	$('#user_dg_table').datagrid('reload');
			        $.messager.alert('提示',data,'info');
					
			  }
		});
	}
  $('#user_dg_table').datagrid({
	  	url: '${ctx}/security/security_getUserListJoson.do',
	  	singleSelect:true,
		rownumbers: true,
		fitColumns:true,
		border:false,
		fit:true,
		columns:[[
			{field:'name',title:'姓名', width:80},
			{field:'logonid',title:'登录账号', width:80},
			{field:'sex',title:'性别', width:80},
			{field:'position',title:'岗位', width:80},
			{field:'status',title:'账号状态', width:80},
			{field:'opt',title:'', width:80,
				formatter: function(value,row,index){
					return '<img onmouseover="this.style.cursor=\'hand\'" onmouseout="this.style.cursor=\'normal\'" onclick="user_del_Fun('+row.id+')" src="${ctx}/css/images/del.png">'
				}
			}
		]],
		toolbar: [{
				text:'新增',
				iconCls: 'icon-add',
				handler:function(){
					user_add_dlg_Fun()
				}
			},{
				text:'编辑',
				iconCls: 'icon-edit',
				handler:function(){
					user_edit_dlg_Fun()
				}
			},{
				text:'删除',
				iconCls: 'icon-remove',  
				handler:function(){
					user_del_Fun()
		   		}
		   	},{
				text:'刷新',
				iconCls: 'icon-reload',  
				handler:function(){
						$('#user_dg_table').datagrid('reload');
				}
			}] 
	})
  
  </script>
  <!-- 列表表格  开始 -->
  <table id="user_dg_table" width="100%" height="100%">
  </table>
  <!-- 列表表格  结束 -->
  </body>
</html>
